# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Sven-Hendrik Haase <svenstaro@gmail.com>
# Contributor: loqs <bugs-archlinux@entropy-collector.net>

pkgname=gitlab-gitaly
pkgver=16.5.1
pkgrel=1
pkgdesc='Speed up Git access using caching'
arch=(loong64 x86_64)
url='https://gitlab.com/gitlab-org/gitaly'
license=(MIT)
depends=(glibc
         libxml2
         libxslt
         libssh2)
makedepends=(cmake
             git
             go)
options=(!buildflags)
backup=("etc/$pkgname/config.toml")
_archive="gitaly-v$pkgver"
source=("$url/-/archive/v$pkgver/$_archive.tar.gz"
        "$pkgname-configs.patch"
        "$pkgname.service")
sha256sums=('c68c209849f7be814f0c18c308d7d11f151f0cc0eebd2cf59b7ebe7e90180818'
            '4257f8fa0c1ca58e25db037ae8ba3bfd83e87e6346e8a4758be21bb87f3cc65d'
            'a047c82481ccbaa3b00ba1bb769135934fa4fa939eb6506d09c77f3a7aec08cd')

prepare() {
	cd "$_archive"
	patch -p1 -i ../$pkgname-configs.patch
	# The patched config should contain no references to '/home/git', URL encoded or otherwise
	grep -vqzE 'home.{1,3}git' config.toml.example
}

build() {
	cd "$_archive"
	pushd ruby
	gem-2.7 sources -r https://rubygems.org/
	gem-2.7 sources -a https://rubygems.loongnix.cn
	gem-2.7 sources -c
#  bundle-2.7 config force_ruby_platform true # build from sources as some prebuilt gems are not available for newer ruby
#  bundle-2.7 install --path vendor/bundle
	popd
	make V=1 BUILD_TAGS="tracer_static tracer_static_jaeger"
}

package() {
	cd "$_archive"
	make PREFIX=/usr DESTDIR="$pkgdir" install
	mkdir -p "$pkgdir/usr/share/webapps/gitlab-gitaly"
	install -Dm0644 config.toml.example "$pkgdir/etc/$pkgname/config.toml"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
	install -Dm0644 -t "$pkgdir/usr/lib/systemd/system/" ../gitlab-gitaly.service
}
